(ns admin-framework.core
  (:gen-class)
  (:use admin-framework.util
        [cheshire.core]
        [cheshire.factory]))


(require 'admin-framework.transaction)
(import 'org.jboss.netty.channel.ChannelFactory
        'org.jboss.netty.channel.SimpleChannelHandler
        'java.util.concurrent.Executors
        'java.net.InetSocketAddress
        'org.jboss.netty.channel.Channels
        'org.jboss.netty.channel.ChannelFactory
        'org.jboss.netty.buffer.ChannelBuffers
        'org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory
        'org.jboss.netty.bootstrap.ServerBootstrap
        'org.jboss.netty.channel.SimpleChannelHandler
        'org.jboss.netty.channel.group.DefaultChannelGroup
        'org.jboss.netty.handler.codec.string.StringEncoder
        'java.nio.charset.Charset
        'org.jboss.netty.util.CharsetUtil
        'admin_framework.transaction)

(def port 9088)

(def channel-handler (transaction.))

(defn handler-func [boot]
  (.. boot getPipeline (addLast "handler" channel-handler ())))

(defn -main [& args]
  (let [fac (NioServerSocketChannelFactory. (Executors/newCachedThreadPool)
                                            (Executors/newCachedThreadPool))
        boot (ServerBootstrap. fac)
        pipe (.getPipeline boot)]
    (.addLast pipe "handler" (transaction.))
    (.addLast pipe "stringEncoder" (StringEncoder. (CharsetUtil/UTF_8)))
    (.setOption boot "child.tcpNoDelay" true)
    (.setOption boot "child.keepAlive" true)
    (.bind boot (InetSocketAddress. port))))

